package com.shixj.easy.spider.api.async;

import com.shixj.easy.spider.constant.DomainContants;
import com.shixj.easy.spider.executor.FetchExecutor;
import com.shixj.easy.spider.model.RegexConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by shixj on 2018/1/15.
 * 笔趣阁http://www.biquge.com.tw
 */
@RestController
@RequestMapping("/async/")
public class DefaultFetchController {
    @Autowired
    @Qualifier("defultFetchExecutor")
    private FetchExecutor executor;
    @GetMapping("novel/{domain}/{sourceId}")
    String fetch(@PathVariable String domain,@PathVariable String sourceId ) {
        String baseUrl=DomainContants.getDomain(domain);
        RegexConfig config = RegexConfig.build().
                setNovelPageRegex(baseUrl + sourceId + "/?")
                .setChapterPageRegex(baseUrl + sourceId + "/\\d+.html$")
                .setInitUrl(baseUrl + sourceId+"/");
        executor.init(config);
        return "ok";
    }
}
